<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加新闻</title>
</head>

<body background="pic/ManBgroud.gif">
	<form action="AddNews" method="post">
	<%--从编辑页面点击标题跳转到此。bug：当没有点击新增新闻时，板块会出现获取不到的情况  
		解决：考虑把GetBoard这个servlet重构成监听器，拦截请求addnews页面和editBoard页面 --%>
	新闻标题<input type="text" name="title" size="100" value="${sessionScope.news[param.clickedId].title}"><br/><br/>
	新闻内容<textarea name="context" style="width:729px;height:600px;">${sessionScope.news[param.clickedId].context}</textarea><br/><br/>
	所属板块<select name="board">
		<%--
		List<BoardInfo> lb=(List<BoardInfo>)session.getAttribute("boards");
			if(lb!=null){
				int i=0;
				for(BoardInfo b:lb){
					out.println("<option value="+i+">"+b.getbName()+"</option>");
					i++;
				}
			}
		--%>
	<c:forEach items="${sessionScope.boards}" var="b" varStatus="vs">
		<option value="${vs.count-1}">${b.bName}</option>
	</c:forEach>		
	</select><br/><br/>
<c:if test="${not empty param.clickedId}"><%--不为空  则修改 --%>
	<input type="submit" formaction="AddNews?clickedId=${param.clickedId}" value="确认修改"/>
</c:if>
<c:if test="${empty param.clickedId}">
	<input type="submit" formaction="AddNews" value="确认新增"/>
</c:if>
	</form>
<c:if test="${sessionScope.addNewsSucc eq true}">
	<c:set var="addNewsSucc" value="${null}"/>
	<script>alert('操作成功');</script>
</c:if>
<c:if test="${sessionScope.addNewsSucc eq false}">
	<c:set var="addNewsSucc" value="${null}"/>
	<script>alert('操作失败');</script>
</c:if>	
</body>
<%--
	Object addNewsSucc=session.getAttribute("addNewsSucc");
	if(addNewsSucc!=null){
		if(addNewsSucc.equals(true)){
			out.println("<script>alert('添加新闻成功')</script>");
		}
		else{
			out.println("<script>alert('添加新闻失败')</script>");
		}
		session.setAttribute("addNewsSucc",null);	
	}
--%>
</html>